# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=re2
pkgver=2024.05.01
_pkgver=${pkgver//./-}
pkgrel=0
pkgdesc="Efficient, principled regular expression library"
url="https://github.com/google/re2"
arch="all"
license="BSD-3-Clause"
makedepends="
	abseil-cpp-dev
	cmake
	icu-dev
	samurai
	py3-gpep517
	py3-setuptools
	py3-wheel
	py3-pybind11-dev
	python3-dev
	"
checkdepends="
	benchmark-dev
	gtest-dev
	"
subpackages="$pkgname-dev py3-$pkgname-pyc:pyc py3-$pkgname:py3"
provides="libre2=$pkgver-r$pkgrel"
source="$pkgname-$pkgver.tar.gz::https://github.com/google/re2/archive/$_pkgver.tar.gz"
builddir="$srcdir"/$pkgname-$_pkgver

build() {
	export CXXFLAGS="$CXXFLAGS -O2 -flto=auto"
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DBUILD_SHARED_LIBS=ON \
		-DRE2_USE_ICU=ON \
		-DRE2_BUILD_TESTING="$(want_check && echo ON || echo OFF)"
	cmake --build build
	# python build
	cd python
	export CPATH=:$builddir
	export LIBRARY_PATH=:$builddir/build
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	ctest --test-dir build --output-on-failure
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	cd "$builddir"/python
	python3 -m installer -d "$pkgdir" \
		.dist/*.whl
}

py3() {
	pkgdesc="Python3 wrapper for Google re2"
	depends="py3-pybind11"
	install_if="$pkgname=$pkgver-r$pkgrel python3"

	amove usr/lib/python*
}

sha512sums="
f6ba22b1d3fdb4c9a6932fd3da6142bbe4617f173a21692878f30210922be3fc550f3a84f84ff1859e3a4235c29946369800c6c848b17af75679eeab3cef2167  re2-2024.05.01.tar.gz
"
